package com.mayqlzu.scrollviewevent;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.alipay.euler.andfix.patch.PatchManager;
import com.baidu.android.pushservice.PushConstants;
import com.baidu.android.pushservice.PushManager;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends Activity {
    MyListView mListView;
    List<String> mList;
    Button btn;
    @Override
    protected void onResume() {
        super.onResume();
        // 启动百度push
            PushManager.resumeWork(getApplicationContext());

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        btn= (Button) findViewById(R.id.btn_resume);
        PushManager.startWork(getApplicationContext(), PushConstants.LOGIN_TYPE_API_KEY,
                    Utils.getMetaValue(this, "api_key"));

        PatchManager patchManager =
                MyApplication.getInstance().getPatchManager();
//        patchManager.init("1.0");
//        patchManager.loadPatch();

        mListView = (MyListView) findViewById(R.id.list_view);
        mList = new ArrayList<>();
        mList.add("kxtx11");
        mList.add("kxtx11");
        mList.add("kxtx11");
        mList.add("kxtx1");
        mList.add("kxtx14");
        mList.add("kxtx12");
        mList.add("kxtx13");
        mList.add("kxtx14");
        mList.add("kxtx1");
        mList.add("kxtx13");
        mList.add("kxtx1");
        mList.add("kxtx1");
        mList.add("kxtx12");
        mList.add("kxtx1");
        mList.add("kxtx14");
        mList.add("kxtx11");
        mList.add("kxtx1");
        mList.add("kxtx12");
        mList.add("kxtx1");
        mList.add("kxtx14");
        mList.add("kxtx1");
        mList.add("kxtx1");
        mListView.setAdapter(new MyAdapter());
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                Intent intent = new Intent(getApplicationContext(), MainActivity.class);
//                PendingIntent restartIntent = PendingIntent.getActivity(
//                        getApplicationContext(), 0, intent,
//                        Intent.FLAG_ACTIVITY_NEW_TASK);
//                //退出程序
//                AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
//                mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 1000,
//                        restartIntent); // 1秒钟后重启应用
//                android.os.Process.killProcess(android.os.Process.myPid());
            }
        });
    }

    class MyAdapter extends BaseAdapter {
        LayoutInflater mInflater;

        public MyAdapter() {
            mInflater = LayoutInflater.from(MainActivity.this);
        }

        @Override
        public int getCount() {
            return mList.size();
        }

        @Override
        public Object getItem(int i) {
            return mList.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder holder;
            if (view == null) {
                holder = new ViewHolder();
                view = mInflater.inflate(R.layout.item, null);
                holder.tv = (TextView) view.findViewById(R.id.tv_txt);
                view.setTag(holder);
            } else {
                holder = (ViewHolder) view.getTag();
            }
            holder.tv.setText((String) getItem(i));

            return view;
        }

        class ViewHolder {
            public TextView tv;
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        PushManager.stopWork(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}